<% layout('/layouts/default.html', {title: 'tk_task管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('任务管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('tk:tkTask:edit')){ %>
					<a href="${ctx}/tk/tkTask/form" class="btn btn-default btnTool" title="${text('新增tk_task')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${tkTask}" action="${ctx}/tk/tkTask/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<#form:hidden path="taskStatus"/>
				<div class="form-group">
					<label class="control-label">${text('项目名称/APP名称')}：</label>
					<div class="control-inline">
						<#form:input path="projectName" maxlength="255" class="form-control width-120"/>
					</div>
				</div>

				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm isQuick">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
				<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	shrinkToFit: false,
	columnModel: [
		{header:'${text("项目名称/APP名称")}', name:'projectName', index:'a.project_name', width:150, align:"left", frozen:true},
		{header:'${text("类型")}', name:'taskType', width:150, align:"left", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('tk_type')}, val, '${text("未知")}', true);
		}},
		{header:'${text("标题")}', name:'title', index:'a.title', width:150, align:"left"},
		{header:'${text("商家")}', name:'icUser.nicheng', index:'a.user_id', width:150, align:"left"},
		{header:'${text("任务描述")}', name:'explainStr', index:'a.explain', width:150, align:"left"},
		{header:'${text("提交时常")}', name:'submitTimes', index:'a.submit_times', width:150, align:"left"},
		{header:'${text("审核时常")}', name:'examineTimes', index:'a.examine_times', width:150, align:"left"},
		{header:'${text("操作设备类型")}', name:'devType', index:'a.dev_type', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('task_dev_type')}, val, '${text("未知")}', true);
		}},
		{header:'${text("做单方式")}', name:'zuodanNumType', index:'a.zuodan_num_type', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('tk_zuodan_num_type')}, val, '${text("未知")}', true);
		}},
		{header:'${text("悬赏单价")}', name:'price', index:'a.price', width:150, align:"right", formatter: function(val, obj, row, act){
			return js.formatNumber(val, 2, false, ''); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
		}},
		{header:'${text("悬赏名额")}', name:'yuDoNum', index:'a.yu_do_num', width:150, align:"center"},
		{header:'${text("预付赏金")}', name:'yufuJine', index:'a.yufu_jine', width:150, align:"right", formatter: function(val, obj, row, act){
			return js.formatNumber(val, 2, false, ''); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
		}},
		{header:'${text("做单次数")}', name:'zuodanNum', index:'a.zuodan_num', width:150, align:"center"},
		// {header:'${text("做单步骤")}', name:'buzhouList', index:'a.buzhou_list', width:150, align:"left", formatter: function(val, obj, row, act){
		// 	return '<a href="javascript:;" class="btnList" title="${text("审核")}">查看</a>';
		// }},
		{header:'${text("创建时间")}', name:'createTime', index:'a.create_time', width:150, align:"center"},
		{header:'${text("操作")}', name:'actions', width:120, formatter: function(val, obj, row, act){
			var actions = [];
			actions.push('<a href="${ctx}/tk/tkTask/taskInfo?id='+row.id+'" class="btnList" title="${text("详情")}">详情</a>&nbsp;');
			if(row.taskStatus==0){
				actions.push('<a href="javascript:;" onclick="shenhe(\''+row.id+'\')" class="" title="${text("审核")}">审核</a>&nbsp;');
			}
			if(row.taskStatus==1){
				actions.push('<a href="javascript:;" onclick="xiajia(\''+row.id+'\')" class="" title="${text("审核")}">违规下架</a>&nbsp;');
			}

			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
</script>
<script id="shenheTask" type="text/template">
	<form id="inputForm" action="${ctx}/tk/tkTask/save" method="post" enctype="multipart/form-data"
		  class="form-horizontal mt20 mb10" style="overflow:auto;max-height:200px;">
		<div class="row">
			<div class="col-xs-12 col-xs-offset-1">
				<input type="hidden" id="id" name="id" class="form-file"/>
				<input type="hidden" id="taskStatus" name="taskStatus" class="form-file"/>
				<label class="control-label col-sm-1" title="">
					<span class="required hide">*</span> <i class="fa icon-question hide"></i></label>
				<div class="col-sm-10">
					<#form:textarea name="failExplain" rows="4" placeholder="未通过原因" maxlength="100"  class="form-control"/>
				</div>
			</div>
		</div>
	</form>
</script>
<script>
	function shenhe(id){
		js.layer.open({
			type: 1,
			area: ['600px'],
			title: '${text("任务审核")}',
			resize: false,
			scrollbar: true,
			content: js.template('shenheTask'),
			success: function(layero, index){
				layero.find('#id').val(id);
			},
			btn: ['<i class="fa fa-check"></i> ${text("通过")}',
				'<i class="fa fa-ban"></i> ${text("未通过")}',
				'<i class="fa fa-close"></i> ${text("关闭")}'],
			btn1: function(index, layero){
				layero.find('#taskStatus').val("1");
				var form = {
					inputForm: layero.find('#inputForm'),
				};
				js.ajaxSubmitForm(form.inputForm, function(data){
					if(data.result == Global.TRUE){
						js.showMessage("审核结束");
						layero.find('#failExplain').val("");
						page();
						js.layer.closeAll();
					}else{
						js.showErrorMessage(data.message);
					}
				}, "json");
				return false;
			},
			btn2:function (index, layero){
				layero.find('#taskStatus').val("3");
				if(layero.find('#failExplain').val()==""){
					js.showErrorMessage("请填写未通过原因");
					return false;
				}
				var form = {
					inputForm: layero.find('#inputForm'),
				};
				js.ajaxSubmitForm(form.inputForm, function(data){
					if(data.result == Global.TRUE){
						js.showMessage("审核结束");
						page();
						js.layer.closeAll();
					}else{
						js.showErrorMessage(data.message);
					}
				}, "json");
				return false;
			}
		});
	}

	function xiajia(id){
		js.layer.open({
			type: 1,
			area: ['600px'],
			title: '${text("任务下架")}',
			resize: false,
			scrollbar: true,
			content: js.template('shenheTask'),
			success: function(layero, index){
				layero.find('#id').val(id);
			},
			btn: ['<i class="fa fa-check"></i> ${text("违规下架")}',
				'<i class="fa fa-close"></i> ${text("关闭")}'],
			btn1: function(index, layero){
				layero.find('#taskStatus').val("4");
				var form = {
					inputForm: layero.find('#inputForm'),
				};
				js.ajaxSubmitForm(form.inputForm, function(data){
					if(data.result == Global.TRUE){
						js.showMessage("下架成功");
						layero.find('#failExplain').val("");
						page();
						js.layer.closeAll();
					}else{
						js.showErrorMessage(data.message);
					}
				}, "json");
				return false;
			},
		})
	}
</script>